package com.liuxvru.project.system.controller;

import com.liuxvru.common.annotation.Log;
import com.liuxvru.common.core.controller.BaseController;
import com.liuxvru.common.core.domain.AjaxResult;
import com.liuxvru.common.core.page.TableDataInfo;
import com.liuxvru.common.enums.BusinessType;
import com.liuxvru.common.utils.poi.ExcelUtil;
import com.liuxvru.project.domain.TicketWorkRelation;
import com.liuxvru.project.service.ITicketWorkRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 工单与工作项的关联Controller
 *
 * @author liuxvru
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/project/ticketWorkRelation")
public class TicketWorkRelationController extends BaseController {
    @Autowired
    private ITicketWorkRelationService ticketWorkRelationService;

    /**
     * 查询工单与工作项的关联列表
     */
    @PreAuthorize("@ss.hasPermi('project:ticketWorkRelation:list')")
    @GetMapping("/list")
    public TableDataInfo list(TicketWorkRelation ticketWorkRelation) {
        startPage();
        List<TicketWorkRelation> list = ticketWorkRelationService.selectTicketWorkRelationList(ticketWorkRelation);
        return getDataTable(list);
    }

    /**
     * 导出工单与工作项的关联列表
     */
    @PreAuthorize("@ss.hasPermi('project:ticketWorkRelation:export')")
    @Log(title = "工单与工作项的关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TicketWorkRelation ticketWorkRelation) {
        List<TicketWorkRelation> list = ticketWorkRelationService.selectTicketWorkRelationList(ticketWorkRelation);
        ExcelUtil<TicketWorkRelation> util = new ExcelUtil<TicketWorkRelation>(TicketWorkRelation.class);
        util.exportExcel(response, list, "工单与工作项的关联数据");
    }

    /**
     * 获取工单与工作项的关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:ticketWorkRelation:query')")
    @GetMapping(value = "/{relationId}")
    public AjaxResult getInfo(@PathVariable("relationId") Long relationId) {
        return success(ticketWorkRelationService.getById(relationId));
    }

    /**
     * 新增工单与工作项的关联
     */
    @PreAuthorize("@ss.hasPermi('project:ticketWorkRelation:add')")
    @Log(title = "工单与工作项的关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TicketWorkRelation ticketWorkRelation) {
        return toAjax(ticketWorkRelationService.save(ticketWorkRelation));
    }

    /**
     * 修改工单与工作项的关联
     */
    @PreAuthorize("@ss.hasPermi('project:ticketWorkRelation:edit')")
    @Log(title = "工单与工作项的关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TicketWorkRelation ticketWorkRelation) {
        return toAjax(ticketWorkRelationService.updateById(ticketWorkRelation));
    }

    /**
     * 删除工单与工作项的关联
     */
    @PreAuthorize("@ss.hasPermi('project:ticketWorkRelation:remove')")
    @Log(title = "工单与工作项的关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{relationIds}")
    public AjaxResult remove(@PathVariable Long[] relationIds) {
        return toAjax(ticketWorkRelationService.removeById(relationIds));
    }
}
